// 记录第三方服务器地址
const host_url = 'https://apis.netstart.cn/yunyuedu';
// 每天必看
export const getColumn = (id) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/column/data.json?id=${id}`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//出版分类
export const getPublish = (type) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/rank/publish/list/data.json?sortType=${type}&type=sell`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//分类列表
export const getClassify = () => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/simpleCategroy.json`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//排行列表
export const getRank = (sex,type) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/rank/original/list/data.json?gender=${sex}&sortType=${type}&type=sell`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//小说详情
export const getDeatil = (id) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/reader/book/info.json?source_uuid=${id}`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//小说筛选
export const getFilter = (id,gender,sort,pay,state) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/category/original/data.json?id=${id}&gender=${gender}&sort=${sort}&pay=${pay}&state=${state}&page=1`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//限时免费
export const getFree = (type) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/limitread/data.json?type=${type}`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//小说内容
export const getNovel = (source_uuid,content_uuid) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/reader/book/content.json?source_uuid=${source_uuid}&content_uuid=${content_uuid}`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//搜索列表
export const getSearchList = (keyword) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/search/book/data.json?key=${keyword}`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}
//评论列表
export const getCommit = (bookId) => {
	return new Promise((resolve, reject) => {
		// uni-app 网络请求接口
		uni.request({
			url: `${host_url}/sns/comment/get.json?type=2&id=${bookId}&page=1`,
			method: "GET",
			success(content) {
				let {
					errMsg,
					data
				} = content;
				if (errMsg == "request:ok") {
					resolve(data)
				} else {
					resolve({
						code: -1,
						msg: '请求失败。'
					})
				}
			}
		})
	})
}